<template>
  <div class="hotRange" :style="themeStyle">
    <div id="heatmapLegend">
      <div class="heatmap-legend">
        <div>{{ rangeNumber.max }}</div>
        <div class="heatmap-legend-color">
          <div class="legend-color-bg" :style="style"> </div>
        </div>
        <div>{{ rangeNumber.min }}</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import { transformWeaterValue, modeList } from './data';
  import { hotLegendColors } from '../constants';
  import { themeStyle } from '../constants';
  const props = defineProps(['hotLegendColor']);
  const getColor = (value) => {
    return value.colors.join(',');
  };

  const hotValue = hotLegendColors?.[transformWeaterValue(modeList[0].value)];

  //默认默认第一个
  const defaultColor = getColor(hotValue);

  let style = ref<any>({
    backgroundImage: `linear-gradient(to top,  ${defaultColor})`,
  });
  let rangeNumber = ref({
    min: hotValue.levels?.[0],
    max: hotValue.levels?.[hotValue.levels?.length - 1],
  });

  watch(
    props,
    () => {
      style.value = {
        backgroundImage: `linear-gradient(to top,${getColor(props.hotLegendColor)} )`,
      };
      rangeNumber.value = {
        min: props.hotLegendColor.levels?.[0],
        max: props.hotLegendColor.levels?.[props.hotLegendColor.levels?.length - 1],
      };
    },
    { deep: true },
  );
</script>
<style lang="less" scoped>
  .hotRange {
    width: 46px;
    height: 266px;
    background: #fff;
    position: absolute;
    top: 30%;
    left: 24px;
    padding-top: 10px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    text-align: center;

    #heatmapLegend {
      .heatmap-legend {
        display: flex;
        align-items: center;
        font-size: 14px;
        flex-direction: column;
        color: #808faf;

        .legend-color-bg {
          width: 16px;
          height: 204px;

          border-radius: 100px;
        }

        .legend-color-tooltip {
          position: absolute;
          display: flex;
          align-items: center;

          .tooltip-content {
            width: 80px;
            height: 24px;
            line-height: 24px;
            text-align: center;
            background: #709eed;
            box-shadow: 0px 5px 12px 4px rgba(200, 201, 204, 0.05),
              0px 3px 6px 0px rgba(200, 201, 204, 0.1), 0px 1px 2px -2px rgba(200, 201, 204, 0.1);
            color: #fff;
          }

          .tooltip-arrow {
            width: 0px;
            height: 0px;
            border: 6px solid transparent;
            border-right-color: #709eed;
          }
        }
      }
    }
  }
</style>
